#include "StdAfx.h"
#include "XIEConfig.h"
#include "XIE.h"


CXIEConfig* CXIEConfig::m_pInstance;


CXIEConfig::CXIEConfig(void)
{
	m_pInstance =  NULL;
}

CXIEConfig::~CXIEConfig(void)
{
}

CSearchEngineList::~CSearchEngineList()
{
	Clean();
}

void CSearchEngineList::Clean()
{
	tagSearchEnginElememt* item;
	for (int i=0;i <= m_Searchs.GetUpperBound();i++)
	{
		item = m_Searchs.GetAt(i);
		delete item;
	}
	m_Searchs.RemoveAll();
}

int CSearchEngineList::Lookup(LPCTSTR key, CString& rValue)
{
	for (int i=0;i <= m_Searchs.GetUpperBound();i++)
	{
		if(m_Searchs.ElementAt(i)->name == key)
		{
			rValue = m_Searchs.ElementAt(i)->url;
			return i;
		}
	}
	return -1;
}

int CSearchEngineList::GetIconIndex(int nIndex)
{
	int nCount = 0;
	for (int i=0;i <= m_Searchs.GetUpperBound();i++)
	{
		if(m_Searchs.ElementAt(i)->icon.GetLength())
		{
			if (nCount==nIndex)
				return i;
			nCount++;
		}
	}
	return -1;
}

BOOL CSearchEngineList::LoadSearchList()
{
	m_nIconCount = 0;
	//
	tagSearchEnginElememt *item;
	TCHAR key[10];
	CString url, alias, icon;
	int r = TRUE;
	int i = 0,rlens;
	int state ;
	TCHAR buf[1024];

	CString filename = GetUserPath() + _T("SearchEngine.ini");
	while(r)
	{
		key[0] = _T('N');
		_itot(i, key+1, 10);
		rlens = ::GetPrivateProfileString(_T("SearchEngine"), key, _T(""), buf, 1024, filename);
		if(rlens==0)
			r=FALSE;
		else
		{
			alias = buf;
			//
			key[0] = 'S';
			_itot(i, key+1, 10);
			rlens = ::GetPrivateProfileString(_T("SearchEngine"), key, _T(""), buf, 1024, filename);
			url = buf;
			//
			key[0] = 'C';//selected
			state = ::GetPrivateProfileInt(_T("SearchEngine"), key, 0, filename);
			//
			key[0] = 'I';//icon
			_itot(i, key+1, 10);
			rlens = ::GetPrivateProfileString(_T("SearchEngine"), key, _T(""), buf, 1024, filename);
			icon = buf;
			//
			item = new tagSearchEnginElememt;
			item->state = state;
			item->name = alias;
			item->url = url;
			item->icon = icon;
			m_Searchs.Add(item);
			if (icon.GetLength())
				m_nIconCount++;
		}
		i++;
	}

	return TRUE;
}

CLastClosedList::CLastClosedList()
{
	Load();
}

CLastClosedList::~CLastClosedList()
{
	Save();
}

BOOL CLastClosedList::Load()
{
	return TRUE;
}

BOOL CLastClosedList::Save()
{
	return  TRUE;
}

tagLastCloseEmlemt*	CLastClosedList::GetByIndex(int nIndex)
{
	return NULL;
}

BOOL CLastClosedList::Add(CString strTitle, CString strURL)
{
	return TRUE;
}

BOOL CLastClosedList::Remove(int nIndex)
{
	return TRUE;
}